package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Elderly;
import com.ruoyi.system.mapper.ElderlyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CheckInNurseRecordMapper;
import com.ruoyi.system.domain.CheckInNurseRecord;
import com.ruoyi.system.service.ICheckInNurseRecordService;

/**
 * 老人护理管理Service业务层处理
 *
 * @author ruoyi
 * @date 2023-02-15
 */
@Service
public class CheckInNurseRecordServiceImpl implements ICheckInNurseRecordService
{
    @Autowired
    private CheckInNurseRecordMapper checkInNurseRecordMapper;
    @Autowired
    private ElderlyMapper elderlyMapper;

    /**
     * 查询老人护理管理
     *
     * @param id 老人护理管理主键
     * @return 老人护理管理
     */
    @Override
    public CheckInNurseRecord selectCheckInNurseRecordById(Long id)
    {
        return checkInNurseRecordMapper.selectCheckInNurseRecordById(id);
    }

    /**
     * 查询老人护理管理列表
     *
     * @param checkInNurseRecord 老人护理管理
     * @return 老人护理管理
     */
    @Override
    public List<CheckInNurseRecord> selectCheckInNurseRecordList(CheckInNurseRecord checkInNurseRecord)
    {
        return checkInNurseRecordMapper.selectCheckInNurseRecordList(checkInNurseRecord);
    }

    /**
     * 新增老人护理管理
     *
     * @param checkInNurseRecord 老人护理管理
     * @return 结果
     */
    @Override
    public int insertCheckInNurseRecord(CheckInNurseRecord checkInNurseRecord)
    {
        checkInNurseRecord.setCreateTime(DateUtils.getNowDate());
        Elderly elderly = elderlyMapper.selectElderlyById(checkInNurseRecord.getPersonId());
        if(elderly != null){
            checkInNurseRecord.setElderName(elderly.getName());
        }
        return checkInNurseRecordMapper.insertCheckInNurseRecord(checkInNurseRecord);
    }

    /**
     * 修改老人护理管理
     *
     * @param checkInNurseRecord 老人护理管理
     * @return 结果
     */
    @Override
    public int updateCheckInNurseRecord(CheckInNurseRecord checkInNurseRecord)
    {
        checkInNurseRecord.setUpdateTime(DateUtils.getNowDate());
        Elderly elderly = elderlyMapper.selectElderlyById(checkInNurseRecord.getPersonId());
        if(elderly != null){
            checkInNurseRecord.setElderName(elderly.getName());
        }
        return checkInNurseRecordMapper.updateCheckInNurseRecord(checkInNurseRecord);
    }

    /**
     * 批量删除老人护理管理
     *
     * @param ids 需要删除的老人护理管理主键
     * @return 结果
     */
    @Override
    public int deleteCheckInNurseRecordByIds(Long[] ids)
    {
        return checkInNurseRecordMapper.deleteCheckInNurseRecordByIds(ids);
    }

    /**
     * 删除老人护理管理信息
     *
     * @param id 老人护理管理主键
     * @return 结果
     */
    @Override
    public int deleteCheckInNurseRecordById(Long id)
    {
        return checkInNurseRecordMapper.deleteCheckInNurseRecordById(id);
    }
}
